/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FileManager;

import java.io.*;
import javax.microedition.lcdui.List;

/**
 *
 * @author zezz
 */
public class FileManager {

    InputStream is;
    OutputStream os;
    InputStreamReader isr;

    public FileManager(String filename) {
        is = this.getClass().getResourceAsStream(filename);

        try {
            isr = new InputStreamReader(is, "UTF-8");
        } catch (Exception ex) {
            //..
        }
    }
    //Return List 

    public List ReadLineList() {
        StringBuffer sb = new StringBuffer();
        List lst = new List(null, List.IMPLICIT);

        try {
            int chars;
            while ((chars = is.read()) != -1) {
                if ((char) chars != '|') {
                    sb.append((char) chars);
                } else {

                    lst.append(sb.toString(), null);
                    sb.delete(0, sb.length());
                }
            }
            return lst;
        } catch (Exception e) {
        }
        return null;
    }
    //Return String Array

    public String[] ReadLineString() {
        StringBuffer sb = new StringBuffer();
        String a[] = new String[10];

        int i = 0;
        try {
            int chars;
            while ((chars = is.read()) != -1) {
                if ((char) chars != '|') {
                    sb.append((char) chars);
                } else {
                    a[i] = sb.toString();
                    i++;
                    sb.delete(0, sb.length());
                }
            }
            return a;
        } catch (Exception e) {
        }
        return null;
    }
    //Get score
    public int getReadScore(String scoreName) {
        String s = "";
        char a[] = scoreName.toCharArray();
        for (int j = 0; j < a.length; j++) {
            if (a[j] != ' ') {
                s += a[j];
            } else {
                return Integer.parseInt(s);
            }
        }
        return 0;
    }
    //Get list score
    public int[] getReadListScore(String[] scores){
        int lstScore[]=new int[10];
        for (int i = 0; i < scores.length; i++) {
            String s = scores[i].toString();
            int score=getReadScore(s);
            lstScore[i]=score;
        }
        return lstScore;
    }
}
